$().ready(function(){
    loadOrderCount();  //统计订单数
    clickEvent();
});

function loadOrderCount(days){
    var url = window.basePath+"/order/countOrdersByStatusFromDay?days="+days;
    $.ajax({
        url:url,
        data:null,
        method:"post",
				headers: {"token" : window.token},
        dataType:"json",
        success:function(result){
          //  if(result.itemCount.length>0){
                // 基于准备好的dom，初始化echarts图表
                var myChartA1 = echarts.init(document.getElementById('a1'));
                myChartA1.setOption(option_a1(result));
            //}
        }
    });
}
var subtext="最近一周的数据";
function clickEvent() {
    $("#today").click(function () {
        loadOrderCount(1);
        subtext="当天数据";
    })
    $("#week").click(function () {
        loadOrderCount(7);
        subtext="最近一周的数据";
    })
    $("#month").click(function () {
        loadOrderCount(30);
        subtext="最近一个月的数据";
    })
}

/*a1*/
function option_a1(result){
   var  a1 = {
        title : {
            text: '工单处理情况',
           subtext: subtext,
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient : 'vertical',
            x : 'left',
            data:['待审批','待处理','处理中','驳回','结束','关闭','草稿']
        },// 工单状态    0  待审批  1  待处理  2  处理中 3  驳回  4  结束  5 关闭  6 草稿
        calculable : true,
        series : [
            {
                name:'数量',
                type:'pie',
                radius : '55%',
                center: ['50%', '60%'],
                data:[
                    {value:result.count0, name:'待审批'},
                    {value:result.count1, name:'待处理'},
                    {value:result.count2, name:'处理中'},
                    {value:result.count3, name:'驳回'},
                    {value:result.count4, name:'结束'},
                    {value:result.count5, name:'关闭'},
                    {value:result.count6, name:'草稿'}
                ]
            }
        ]
    };
    return a1;
}
